/**
 * 创建者：luyiming
 * 该页面用于：
 * 创建时间： 2020-03-06 21:47:02
 */
import Table from "@/components/Table";
import Pagination from "@/components/Pagination"; // 分页
import ReportTable from "@/components/luyiming/ReportTable/index.vue";
import AbnormalTemplate from "@/template/abnormal.temp.vue";
import { getDelarationRateList, getDelarationRateDetailList, getDelarationRateDetailInfo, getReport } from "@/api/RCIM/RCIM-source";
import {
	cloneDeep
} from "lodash";
import moment from "moment";
export default {
	name: 'RcimSourceStatistics_view',
	components: {
		Table,
        Pagination,
        ReportTable,
		AbnormalTemplate,
	},
	// 数据
	data() {
		return {
			datePickType: {
				format: "yyyy-MM",
				precise: "month",
				longer: "30"
			},
			tableData: [],
			tableHead: [],
			tableHeadOne: [{
					id: 'enterprise',
					name: '企业',
					width: "",
					align: "center"
				},
				{
					id: 'sourceNumber',
					name: '放射源备案源数',
					width: "",
					align: "center"
				},
				{
					id: 'sourceDeclareNumber',
					name: '放射源申报次数',
					width: "",
					align: "center"
				},
				{
					id: 'sourceDeclareRate',
					name: '放射源申报率',
					width: "",
					align: "center"
				},
				{
					id: 'rayDeclareNumber',
					name: '射线装置申报次数',
					width: "",
					align: "center"
				},
				{
					id: 'rayDeclareRate',
					name: '射线装置申报率',
					width: "",
					align: "center"
				},
				{
					id: "operate",
					name: "操作",
					width: "",
					align: "center"
				}
			],
			tableHeadTwo: [{
					id: 'declareTime',
					name: '申报时间',
					width: "",
					align: "center"
				},
				{
					id: 'sourceNumber',
					name: '放射源备案源数',
					width: "",
					align: "center"
				},
				{
					id: 'sourceRealNumber',
					name: '放射源实有源数',
					width: "",
					align: "center"
				},
				{
					id: 'sourceStockNumber',
					name: '放射源在库源数',
					width: "",
					align: "center"
				},
				{
					id: 'sourceUseNumber',
					name: '放射源在用源数',
					width: "",
					align: "center"
				},
				{
					id: 'rayUseNumber',
					name: '射线装置在用台数',
					width: "",
					align: "center"
				},
				{
					id: "operate",
					name: "操作",
					width: "",
					align: "center"
				}
			],
			listLoading: false,
			total: 0,
			listQuery: {
				page: 1,
				limit: 10
			},
			listQuery1: {},
            tableLevel: 1,

			dialogFormVisible: false,
			timeParam: '',
			reportTable: [
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '企业名称',
						key: 'name'
					}]
				},
				{
					col: [{
						fspan: 12,
						span: [12, 12],
						name: '登记人：',
						key: 'registrant'
					},{
						fspan: 12,
						span: [12, 12],
						name: '企业负责人：',
						key: 'chargePerson'
					}]
				},
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '申报日期：',
						key: 'declareTime',
						formType: 'select',
						formTypeC: 'option',
						options: [
							{
								label: '2019-12-11',
								value: '2019-12-11'
							},
							{
								label: '2019-12-13',
								value: '2019-12-13'
							},
							{
								label: '2019-12-20',
								value: '2019-12-20'
							},
						]
					}]

				},
			],
			sorceReport: [
				{
					col: [{
						fspan: 24,
						span: [24, 0],
						name: '放射源（单位/枚）',
						key: null
					}]
				},
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '备案源数',
						key: 'sourceNum'
					}]

				},
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '在用源数',
						key: 'useSourceNum'
					}]

				},
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '在库源数',
						key: 'stockSourceNum'
					}]

				},
			],
			deviceReport: [
				{
					col: [{
						fspan: 24,
						span: [24, 0],
						name: '射线装置（单位/台）',
						key: null
					}]
				},
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '再用台数',
						key: 'useDeviceNum'
					}]

				},
			],
			sourceForm:[],
			deviceForm:[],
			reportSourceTitle: "放射源每日检查登记申报台账",
			reportDeviceTitle: "射线装置每周检查登记申报台账",
			showSourceReport: -1,
		}
	},
	// 监听
	watch: {

	},
	// Vue实例初始化完成
	created() {
        this.sourceForm = cloneDeep(this.reportTable);
		this.sourceForm.splice(1,0,...this.sorceReport);
		this.deviceForm = cloneDeep(this.reportTable);
		this.deviceForm.splice(1,0,...this.deviceReport);
		this.tableLevel = 1
		this.headAssign()
    },
	// Vue挂载完成
	mounted() {

	},
	// Vue实例销毁前
	beforeDestroy() {

	},
	// 挂载的方法
	methods: {
		/**
		 * 表格获取数据
		 */
		getList() {
			this.tableLevel = 1
			this.headAssign()
			this.listLoading = true
			// 接口调用
			getDelarationRateList(this.listQuery).then(res => {
				this.listLoading = false
				this.total = res.data.total
				this.tableData = res.data.data

			})

		},
		/**
		 * @description 获取子集数据
		 * @param {*} row 行数据
		 */
		getDetailList(row) {
			this.tableLevel = 2
			this.headAssign(true)
			this.listLoading = true
			// 接口调用
			getDelarationRateDetailList(this.listQuery1).then(res => {
				this.listLoading = false
				this.tableData = res.data.map(item => {
					// 如果是0，表示射线装置
					if(item.type === 0){
						item.sourceNumber = '-'
						item.sourceRealNumber = '-'
						item.sourceStockNumber = '-'
						item.sourceUseNumber = '-'
					}
					// 如果是1，表示源
					if(item.type === 1){
						item.rayUseNumber = '-'
						item.cellClass = item.sourceNumber === item.sourceRealNumber ? '' : 'staic_denger'
					}
					item.entName = row.enterprise;
					return item;
				})
			})

		},
		/**
		 * 点击树调用函数
		 */
		treeHandle(param) {
			console.log(param);
			let {treeType,time} = param
			Object.assign(this.listQuery,{treeType,date: moment(time).format('YYYY-MM')}, {
				nodeId: param.id,
				nodeType: param.type
			})
			this.getList()
		},
		/**
		 * 表头赋值
		 */
		headAssign(num) {
			if (num) {
				this.tableHead = cloneDeep(this.tableHeadTwo)
			} else {
				this.tableHead = cloneDeep(this.tableHeadOne)
			}
		},
		/**
		 * 获取子级表格
		 */
		detailTable(row) {
			Object.assign(this.listQuery1, {
				id: row.id,
				date: this.listQuery.date,
			})
			this.getDetailList(row)
		},
		/**
		 * 返回上个表格
		 */
		showReturn() {
			this.getList()
        },
		/**
		 * 打开弹窗
		 */
		openDialog(row) {
			this.dialogFormVisible = true;
			this.isReadOnly = false;
			getReport({
				type: row.type,
				id: row.id,
			}).then(res => {
				this.showSourceReport = row.type;
				const defautObj = {
					name: row.entName,
				}
				this.$nextTick(() => {
					// 放射源
					if(this.showSourceReport === 1){
						this.$refs.reportSource.setDefaultValue(Object.assign({
							sourceNum: row.sourceNumber
						},res.data.sourceData, defautObj))
					}
					// 用源设备
					if(this.showSourceReport === 0){
						this.$refs.reportDevice.setDefaultValue(Object.assign({},res.data.deviceData, defautObj))
					}
				})
			})
		},
	},
}
